package testing.strutturale;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import jsudoku.Sudoku;
import jsudoku.SudokuFileManager;
import jsudoku.exception.InvalidSudokuException;

import org.junit.Test;

import testing.utility.Matrice;

public class testSalvaPartita {

	@Test
	public void testSalvaPartita1() {
		
		int[][] matrice = {
				
				{0, 8, 4, 5, 7, 2, 9, 1, 3},
				{9, 3, 2, 8, 6, 1, 7, 5, 4},
				{5, 1, 7, 9, 4, 3, 6, 8, 2},
				{3, 4, 9, 2, 5, 8, 1, 6, 7},
				{1, 6, 8, 3, 9, 7, 4, 2, 5},
				{7, 2, 5, 6, 1, 4, 8, 0, 9},
				{4, 7, 3, 0, 2, 6, 5, 9, 8},
				{2, 5, 1, 4, 8, 9, 3, 7, 6},
				{0, 9, 6, 7, 3, 5, 2, 4, 1}
				
		};
		
		try {
			//creiamo l'oggetto sudoku a partire dalla matrice
			Sudoku s = new Sudoku(matrice);
			//percorso file
			File f = new File("Salva6.sdk");
			//Salviamo il sudoku
			SudokuFileManager manager = new SudokuFileManager(f);
			manager.saveSudoku(s);
			
			//apriamo il file sudoku tramite librerie java
			FileReader fr = new FileReader(f);
			
			BufferedReader br = new BufferedReader(fr);
			
			String matrice_save = br.readLine();
			
			String matrice_init = Matrice.getStringMatrice(matrice);
			
			assertEquals(matrice_save, matrice_init);
			
			br.close();
			
			
		} catch (InvalidSudokuException e) {
			e.printStackTrace();
		} catch (IOException e){
			e.printStackTrace();
		}
	}

}
